<?php
include('connect.php');
print_r($_POST);
//print_r($_cookie);
$action=$_POST["action"];
/*f($action=='add'){
	$shoppingcart_id = $_POST["shoppingcart_id"];

			//getting the item id from the request
			$item_id = $_POST["item"];

			//getting the quantity of items
			$item_quantity = $_POST["quantity"];
		
			//perform the mysql query to link the two elements inside DB
			echo $sql="INSERT INTO REL (ID_CART, ID_ITEM, AMOUNT) VALUES ('$shoppingcart_id', '$item_id', '$item_quantity')";
			mysql_query($sql);
}*/
if(isset($_POST["action"])) //check if the request exists
	{
	switch($_POST["action"]) //verify what kind of request is it
		{
		case "add": //the request is an add request
			//perform task
			
			//getting the cart id from the cookie
			$shoppingcart_id = $_POST["shoppingcart_id"];

			//getting the item id from the request
			$item_id = $_POST["item"];

			//getting the quantity of items
			$item_quantity = $_POST["quantity"];
		
			//perform the mysql query to link the two elements inside DB
			mysql_query("INSERT INTO REL (ID_CART, ID_ITEM, AMOUNT) VALUES ('$shoppingcart_id', '$item_id', '$item_quantity')");
		break;
		case "update": //the request is an update request
			//perform tasl
			
			//getting the cart id from the cookie
			$shoppingcart_id = $_POST["shoppingcart_id"];
			
			//getting the item id from the request
			$item_id = $_POST["item"];
			
			//getting the new quantity inserted in the textarea
			$new_quantity = $_POST["quantity"];
			
			//perform the mysql update
			mysql_query("UPDATE rel SET AMOUNT = '$new_quantity' WHERE ID_CART = '$shoppingcart_id' AND ID_ITEM = '$item_id'");
		break;
		case "delete": //the request is an add request
			//perform task
			
			//getting the cart id from the cookie
			$shoppingcart_id = $_POST["shoppingcart_id"];

			//getting the item id from the request
			$item_id = $_POST["item"];
		
			//perform the mysql query to link the two elements inside DB
			mysql_query("DELETE FROM rel WHERE ID_CART = '$shoppingcart_id' AND ID_ITEM = '$item_id'");
		break;
		}
	}
?>